var agreementInlineFilter = function (options) {
    var _options = options;
    var _agreements;
    var $ = grp.jQuery;

    function init() {
        if (_options.client)
            $.post(_options.url.replace('/0/', ['/', _options.client, '/'].join('')),
                {csrfmiddlewaretoken: $.cookie('csrftoken')},
                function (result) {
                    _agreements = result;
                    filterExistingOps(_options.group);
                });
        else
            cleanOptions();
    }

    function cleanOptions() {
        $("select[name$=agreement]").each(function () {
            $(this).empty();
            $(this).append($("<option value>---------</option>"));
        });
    }

    function filterRow() {
        var select = $("select[name$=agreement]", this);
        if (!select) return;
        var selected = select.val();
        select.empty();
        select.append($("<option value>---------</option>"));
        $.each(_agreements, function (i, value) {
            select.append($("<option></option>")
                .attr("value", value.id).text(value.number));
        });
        select.val(selected);
    }

    function filterExistingOps(group) {
        $("#" + group + " div.grp-tbody div.grp-tr").each(filterRow);
    }

    init();
}